package disjunction.core
{
	import disjunction.core.state.*;
	
	import flash.display.Sprite;
	
	/**
	 * (abstract) Extend this to provide a document class for your game.
	 *
	 * @author Nick Wiggill
	 */
	
	public class Game extends Sprite
	{
		private var _stateMgr:StateManager;
		
		/**
		 * Initialises the game by configuring and starting the startup state.
		 * 
		 * @param startStateId The id of the state in which to begin execution.
		 * @param states A list of States which constitute the game.
		 * @param startStateConfig An object containing configuration for the first state
		 * (and possibly, subsequent ones).
		 */
		
		public function Game()
		{
			_stateMgr = new StateManager();
		}
		
		public function initialise(startStateKey:String, controller:Controller, data:Object):void
		{
			_stateMgr.activateState(startStateKey, new GameStateConfiguration(controller, data));			
		}
		
		public function registerState(state:GameState, id:String = null):void
		{
			if (id != null)
				_stateMgr.registerState(id, state);
			else //use the state's own id to register by
				_stateMgr.registerState(state.id, state);
		}
	}
}